package com.youlin.aop;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ApplicationContextEvent;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

@Component
public class MyApplicationListener implements ApplicationListener<ApplicationContextEvent> {

    @Autowired
    private AsyncService asyncService;

    @Override
    public void onApplicationEvent(ApplicationContextEvent event) {
        if (event instanceof ContextRefreshedEvent) {
            // 重新设置 Redis 预设数据
            asyncService.resetRedisData();

            // 重新设置告别会 UUID 的 Redisson 布隆过滤器
            asyncService.resetRBloomFilter();

            // 重新将小程序配置参数加载到 Redis
            asyncService.switchWxAppletAsync(null);
        }

        if (event instanceof ContextClosedEvent) {

        }
    }

}
